package com.forest.sdk.example.service;

import cn.hutool.json.JSONUtil;
import com.forest.config.SignatureProperties;
import com.forest.dto.ResultResponse;
import com.forest.service.SignatureHttpUtil;
import com.forest.util.AesUtil;
import com.forest.util.EnvironmentHolder;
import com.forest.util.Sm4Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service
public class SdkTestService {


    public String sm4EncryptBase64(String data) {
        return Sm4Util.encryptBase64(data);
    }

    public String sm4EncryptHex(String data) {
        return Sm4Util.encryptHex(data);
    }

    public String sm4Decrypt(String data) {
        return Sm4Util.decrypt(data);
    }

    public String aesEncryptBase64(String data) {
        return AesUtil.encryptBase64(data);
    }

    public String aesEncryptHex(String data) {
        return AesUtil.encryptHex(data);
    }

    public String aesDecrypt(String data) {
        return AesUtil.decrypt(data);
    }

    public String signatureHttpUtilPost() {
        SignatureProperties.AppInfo appInfo = EnvironmentHolder.getAppInfo("1");
        //业务参数
        Map<String,Object> params = new HashMap<>();
        params.put("phone",Sm4Util.encryptBase64("13300001111"));
        ResultResponse<Object> res = SignatureHttpUtil.post(appInfo.getAppId(), "/signature/testVerifySign", params);
        return JSONUtil.toJsonStr(res);
    }

    public String signatureHttpUtilGet() {
        SignatureProperties.AppInfo appInfo = EnvironmentHolder.getAppInfo("1");
        Object data = new Object();
        ResultResponse<Object> res = SignatureHttpUtil.get(appInfo.getAppId(), "/signature/testVerifySign", data);
        return JSONUtil.toJsonStr(res);
    }

    public String signatureHttpUtilPostForEncryption() {
        SignatureProperties.AppInfo appInfo = EnvironmentHolder.getAppInfo("1");
        Object data = new Object();
        ResultResponse<Object> res = SignatureHttpUtil.postForEncryption(appInfo.getAppId(), "/signature/testVerifySignFoeEncryption", data);
        return JSONUtil.toJsonStr(res);
    }


}
